#!/bin/bash 
set -e

TMP=${TMP:-/tmp/work}
LOG=${LOG:-$HOME/logs/stage3}
SRC=${SRC:-/sources}

name=libcap
version=2.48

rm -rf $TMP
mkdir -p $TMP $LOG

tar xf $SRC/$name-$version.tar.xz -C $TMP

{ time \
   {

    cd $TMP/$name-$version
    
    sed -i '/install -m.*STA/d' libcap/Makefile
    
    make prefix=/usr lib=lib
    
    make prefix=/usr lib=lib install
    for libname in cap psx; do
        mv -v /usr/lib/lib${libname}.so.* /lib
        ln -sfv ../../lib/lib${libname}.so.2 /usr/lib/lib${libname}.so
        chmod -v 755 /lib/lib${libname}.so.$version
    done

    }
} 2>&1 | tee $name.log
    
[ $PIPESTATUS = 0 ] && mv $name.log $LOG || exit $PIPESTATUS

rm -fr $TMP
